
capture log close

set more off
set matsize 10000


use rep_final, clear

	*noncitizens
	keep if cit==0
	*married last year, currently still married with spouse present
	keep if marrinyr==2 & married==1 
	*spouse info is avail.
	drop if citizen_sp==.

* Define control variables 

	local demog "age age2 male yreduc i.racegr"	
	local imm "ysm i.bpl " 
	local fe "i.statefip i.yrmarr "
		
	local full "`demog' `imm' `fe' "
		
		
	keep if year>=2012
	replace gtindex=log(gtindex+1)
	g treatgt=treatgr*gtindex

	
*******************************************************************
*Table 5-Panel A

* Use gtindex at state-year level as independent varaible, by gender
	
	local a=1
	foreach gender of varlist female male {
		preserve
		keep if `gender'==1
		foreach depvar of varlist cit_sp  {
			
			display ""
			display "--------------------------------------"
			
			display "Dependent Variable: `depvar' "

			display "--------------------------------------"
	
			
			reg `depvar' gtindex treatgr treatgt `full' ///
				if daca==1|controlgrdaca==1  [pweight = perwt] , cluster(statefip)
			est sto e`a'
					
			local a=`a'+1
			}
		
		*dep var mean
	
		sum cit_sp [fweight=perwt] if e(sample) 
		
			*Make table
			
			esttab e1 e2 ///
					using table5_panelA.csv, se  ///
					mtitles("Female" "Male") ///
					title(Intermarriage Rate) ///
					b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) ///
					nogaps replace

		restore
		}		

*********************************************************************
*Table 5-Panel B



	local a=1
	foreach gender of varlist female male {
		preserve
		keep if `gender'==1
		foreach depvar of varlist cit_sp  {
			
			display ""
			display "--------------------------------------"
			
			display "Dependent Variable: `depvar' "

			display "--------------------------------------"
	

			reg `depvar' gtindex treatgr treatgt `full' ///
				i.statefip##c.yrmarr dacacount ///
				if daca==1|controlgrdaca==1  [pweight = perwt] , cluster(statefip)			
			est sto e`a'
					
			local a=`a'+1
			}
		
		*dep var mean
		sum cit_sp [fweight=perwt] if e(sample) 
		
			*Make table
			
			esttab e1 e2 ///
					using table5_panelB.csv, se  ///
					mtitles("Female" "Male") ///
					title(Intermarriage Rate) ///
					b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) ///
					nogaps replace

		restore
		}	





